package com.rongshu.view.userInfo.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.rongshu.R;
import com.rongshu.view.userInfo.entity.CardBagInfo;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class CardBagAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context mContext = null;

    private List<CardBagInfo.ResponseBean> cardBagInfos = null;

    public CardBagAdapter(Context context) {
        this.mContext = context;
    }

    public void setCardBagInfos(List<CardBagInfo.ResponseBean> list) {
        this.cardBagInfos = list;
    }

    public List<CardBagInfo.ResponseBean> getCardBagInfos() {
        return this.cardBagInfos;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_card_bag_item_view, parent, false);
        return new CardBagViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        CardBagInfo.ResponseBean cardBagInfo = cardBagInfos.get(position);
        CardBagViewHolder viewHolder = (CardBagViewHolder) holder;
        viewHolder.txt_card_name.setText(cardBagInfo.getProps());
        viewHolder.txt_card_sum.setText("累计数量 " + cardBagInfo.getCount() + "张 (每次推荐使用一张)");
    }

    @Override
    public int getItemCount() {
        if (cardBagInfos != null) {
            return cardBagInfos.size();
        }
        return 0;
    }

    public static class CardBagViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_card_name)
        TextView txt_card_name;
        @BindView(R.id.txt_card_sum)
        TextView txt_card_sum;

        public CardBagViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
